from django.db import models

from Administrative_office_system.utils.BaseModel import BaseModel
from personal_center.models import User


class Notice(BaseModel):
    STATE = (
        ('one', '分管领导'),
        ('two', '医院办公室'),
        ('end', '结束'),
        ('stop', '中止'),
        ('eight', '拒绝'),
    )
    TYPE = (('app', 'app'),
            ('pc', 'pc'))
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    type = models.CharField('来源', max_length=10, choices=TYPE, default='pc')
    name = models.CharField(max_length=255, verbose_name='公告名称')
    is_open = models.CharField(max_length=20, verbose_name='是否公开')
    announcement_time = models.CharField(max_length=100, verbose_name='公告时间')
    content = models.TextField(verbose_name="公告内容")
    create_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="创建人",
        related_name='Notice_create_people',
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审核人",
        related_name='Notice_audit_people',
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    already_users = models.ManyToManyField('personal_center.User', verbose_name='已办人员', related_name='notice_already_users', blank=True, default='')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='notice_audit_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='notice_already_audit_users', blank=True)
    adjunct = models.TextField(verbose_name="附件")
    pdf_path_list = models.TextField(verbose_name="pdf文件列表", default='')
    uuid = models.CharField(max_length=50, verbose_name='附件唯一ID', default='')
    class Meta:
        verbose_name = '通知公告'
        verbose_name_plural = verbose_name

    def get_state_str(self):
        if self.state == "draft":
            return '审核中'
        if self.state == "audit":
            return '完结'
        if self.state == "unaudit":
            return '拒绝'


class AuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '分管领导'),
        ('two', '医院办公室'),
    )

    notice_id = models.ForeignKey(
        'Notice',
        verbose_name="通知公告",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)

    class Meta:
        verbose_name = '审批信息'
        verbose_name_plural = verbose_name

    def get_state_str(self):
        if self.state == "draft":
            return '拒绝'
        if self.state == "audit":
            return '同意'
        if self.state == "unaudit":
            return '待审核'


class NoticePeople(BaseModel):
    STATE = (
        ('accept', '未读'),
        ('accepted', '已读'),
    )
    notice_id = models.ForeignKey(
        'Notice',
        verbose_name="通知公告",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='accept')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="人员",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    accepted_time = models.CharField(max_length=100, verbose_name='接受时间')
    signature_picture = models.CharField(default='', max_length=128, verbose_name='签名')

    class Meta:
        verbose_name = '接受信息'
        verbose_name_plural = verbose_name
